package com.blb.web;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blb.base.BaseServlet;
import com.blb.entity.User;
import com.blb.service.UserService;

@WebServlet("/userIsExist")
public class UserServlet extends BaseServlet {
	
	private static final long serialVersionUID = 1L;
	
	private UserService userService = new UserService();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String username = req.getParameter("username");
		
		try {
			User user = userService.getUserByUserName(username);
			if (user!=null) {
				resp.getWriter().write("用户名已存在");
			}else {
				resp.getWriter().write("");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			resp.getWriter().write(e.getMessage());
		}
	}
}
